<%@page import="user.User"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="inventory.InventoryItem"%>
<%@page import="model.UserPage"%>
<%UserPage u = (UserPage) request.getAttribute("model");%>  
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="css/discover.css"/>
        <script>
            $(document).ready(function() {
                $(".bookDetails").hide();
                
                $(".title").click(function () {
                    if($(this).parent().children(".bookDetails").is(":visible"))
                        $(this).parent().children(".bookDetails").fadeOut(300);
                    else
                        $(this).parent().children(".bookDetails").fadeIn(300);
                });
            });
        </script>
    </head>
    <body>
        <%
        // Get all the books and display who owns them
            ArrayList<User> listOfOwners;
            int divID = 0;

            for (InventoryItem key : u.library.keySet()) {

                listOfOwners = u.library.get(key);
                if (listOfOwners.size() > 1 || listOfOwners.get(0).username.equals(u.user.username) == false) {
                    out.print("<div class='book' id='book" + divID + "'>");
                    out.print("<div class='title' id='title" + divID + "'>" + key.itemName + "</div>");
                    out.print("<div class='bookDetails' id='book" + divID + "'>");
                    out.print("<div class='isbn' id='isbn" + divID + "'>ISBN: " + key.itemISBN + "</div>");
                    out.print("<div class='author' id='author" + divID + "'>Author: " + key.itemAuthor + "</div>");
                    for (int i = 0; i < listOfOwners.size(); i++) {
                        if (listOfOwners.get(i).username != null) {
                            out.print("<div class='owner' id='owner" + i + "'>" + listOfOwners.get(i).username + "</div>");
                        }
                    }
                    out.print("</div>"); // bookDetails
                    out.print("</div>"); // book
                    divID++;
                }
            }
        %>
    </body>
</html>